package com.exp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.exp.dto.NoticeInfDTO;
import com.exp.dto.NoticePageQueryDTO;
import com.exp.interceptor.JwtTokenAdminInterceptor;
import com.exp.mapper.NoticeInfMapper;
import com.exp.pojo.JobInf;
import com.exp.result.PageResult;
import com.exp.service.NoticeInfService;
import com.exp.pojo.NoticeInf;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
* @author 王-自信
* @description 针对表【notice_inf】的数据库操作Service实现
* @createDate 2024-11-18 20:52:05
*/
@Service
public class NoticeInfServiceImpl extends ServiceImpl<NoticeInfMapper, NoticeInf>
    implements NoticeInfService {

    @Autowired
    private NoticeInfMapper noticeInfMapper;

    @Override
    public PageResult pageQuey(NoticePageQueryDTO noticePageQueryDTO) {
        PageHelper.startPage(noticePageQueryDTO.getPage(),noticePageQueryDTO.getPageSize());
        Page<NoticeInf> page = noticeInfMapper.pageQuery(noticePageQueryDTO);
        long total = page.getTotal();
        List<NoticeInf> records = page.getResult();
        return new PageResult(total,records);
    }

    @Override
    public void update(NoticeInfDTO noticeInfDTO) {
        NoticeInf noticeInf = new NoticeInf();
        BeanUtils.copyProperties(noticeInfDTO, noticeInf);
        // 从ThreadLocal中获取userId
        Integer userId = JwtTokenAdminInterceptor.threadLocal.get();
        if (userId != null) {
            // 使用userId进行操作
            noticeInf.setUserId(userId);
        }
        noticeInfMapper.update(noticeInf);
    }

    @Override
    public void deleteBatch(List<Integer> ids) {
        //删除数据
        for (Integer id : ids) {
            noticeInfMapper.deleteById(id);
        }
    }



}




